package com.nondo.dean.platform.controller.api.inner;

import com.alibaba.fastjson.JSONObject;
import com.nondo.dean.common.annotation.ApiVersion;
import com.nondo.dean.platform.domain.Region;
import com.nondo.dean.platform.domain.User;
import com.nondo.dean.platform.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xiaofan
 * @Description:
 * @throws
 * @date 2018-04-1211:21
 * @Version
 */
@RestController("apiInnerUserRegion")
@RequestMapping("/{v}/inner/user")
public class UserRegionController {

    @Autowired
    UserService userService;


    /**
     * 接收sap返回的区域数据入库
     * @param result
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/region")
    public int synRegion(@RequestBody String result){
        Object jsonObject=JSONObject.parse(result);
        String jsonString=jsonObject.toString();

       int res= userService.insertRegion(JSONObject.parseArray(jsonString, Region.class));
       return res;

    }

    /**
     * 接收sap返回的客户数据入库
     * @param result
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/list")
    public int synUser(@RequestBody String result){
        Object jsonObject=JSONObject.parse(result);
        String jsonString=jsonObject.toString();

        return userService.insertUser(JSONObject.parseArray(jsonString, User.class));
    }
}
